/**
 * This class is a subclass of the Hand class, and are used to model a hand of Pair.
 * It overrides getTopCard,isValid and getType method that it inherits from Hand class.
 *
 * @author Jiang Feiyu
 */
public class Pair extends Hand{
    /**
     * Constructor for the Pair type hand. Calls the constructor of Hand super class.
     *
     * @param player Player who plays the hand
     * @param cards  List of card played by the player
     */
    public Pair(CardGamePlayer player, CardList cards) {
        super(player,cards);
    }

    /**
     * Returns the top card of the hand.
     */
    public Card getTopCard() {
        this.sort();
        return this.getCard(1);
    }

    /**
     * Checks whether the hand is a Pair.
     */
    public boolean isValid() {
        if(this.size() == 2) {
            return this.getCard(0).getRank() == this.getCard(1).getRank();
        }
        return false;
    }

    /**
     * Returns type of string.
     */
    public String getType() {
        return "Pair";
    }
}
